package com.class05;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletD")
public class ServletD extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("ServletD执行了.............");
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.sendRedirect("https://www.baidu.com");

//        toService((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse);

    }

//    private static void toService(ServletRequest servletRequest, ServletResponse servletResponse) {
//        try {
//            HttpServletResponse res = null;
//            if (servletRequest instanceof HttpServletRequest && servletResponse instanceof HttpServletResponse) {
//                HttpServletRequest req = (HttpServletRequest) servletRequest;
//                res = (HttpServletResponse) servletResponse;
//                res.sendRedirect("https://www.baidu.com");
//            }
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
}
